package com.pgeg.mixin.skill;

import com.pgeg.api.mana.IManaHandler;
import com.pgeg.listener.ItemListener;
import com.pgeg.listener.StatusEffectListener;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FireballEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Item.class)
public class FireBallSkill {

    @Inject(method = "use", at = @At("RETURN"), cancellable = true)
    private void onFireBallSkill(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
        ItemStack stack = user.getMainHandStack();
        ItemStack stack1 = user.getOffHandStack();
        if (((IManaHandler) user).getMana() > 0) {
            if (stack.isOf(ItemListener.WAND)) {
                if (stack1.isOf(ItemListener.RUNE_FIRE)) {
                    FireballEntity fireball = new FireballEntity(world, user, user.getRotationVector().getX(), user.getRotationVector().getY(), user.getRotationVector().getZ(), 0);
                    fireball.setProperties(user, user.getPitch(), user.getYaw(), 0.0F, 1.5F, 0.0F);
                    world.spawnEntity(fireball);
                    user.addStatusEffect(new StatusEffectInstance(StatusEffectListener.MANA_REDUCTION, 4 * 2, 1));
                }
            }
        }
        cir.setReturnValue(TypedActionResult.success(stack));
    }
}
